    'use strict';
    import Base from './base.js';
    //美易通客户类控制器请求方法
    module.exports = class extends Base {
    //客户列表查询所属客户  ——初步
    async getguestlistAction(){
      let user_id = this.get('user_id');
      let jsonshop = this.get('jsonshop');
      let floor = this.get('floor');
      let ismanage = this.get('ismanage');
      let select_info = this.get('select_info');
      let page = this.get('page');
      let size = this.get('size');
      let nowpage = page * size;

      switch(floor)
      {
        //如果是总部运营和店长
        case '0':
        case '1':
          //统计数量
          if(page == 0){
          var guest_num = await this.model().query(' SELECT count(distinct og.id) as num FROM `think_or_guest` og LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE od.id IN ('+jsonshop+') ' + select_info + ' AND og.isdisable = 0 ');
          }
          //查询该机构下所有的客户
          var guest_info = await this.model().query(' SELECT og.name,og.nickname,og.phone,od.name as shopname,og.sex,og.id,og.headurl,og.lv,og.arrivetime,count(oau.uid) as fuwunum,og.vipcard FROM `think_or_guest` og LEFT JOIN `think_or_department` od ON og.departmentid = od.id LEFT JOIN `think_or_allotuser` oau ON og.id = oau.gid WHERE od.id IN ('+jsonshop+') ' + select_info + ' AND og.isdisable = 0 GROUP BY og.id limit ' + nowpage + ','+size+' ');
        break;
        //如果是经理
        case '2':
          //统计数量
          if(page == 0){
          var guest_num = await this.model().query(' SELECT count(distinct oat.gid) as num FROM `think_or_allotuser` oat LEFT JOIN `think_or_app_user` au ON oat.uid = au.id LEFT JOIN `think_or_guest` og ON oat.gid = og.id LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE au.bumenid = '+jsonshop+' ' + select_info + ' AND og.isdisable = 0 ');
          }
          //查询该机构下所有的客户
          var guest_info = await this.model().query(' SELECT distinct og.name,og.nickname,og.phone,od.name as shopname,og.sex,og.id,og.headurl,og.lv,og.arrivetime,count(oat.uid) as fuwunum,og.vipcard FROM `think_or_allotuser` oat LEFT JOIN `think_or_app_user` au ON oat.uid = au.id LEFT JOIN `think_or_guest` og ON oat.gid = og.id LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE au.bumenid = '+jsonshop+' ' + select_info + ' AND og.isdisable = 0 GROUP BY oat.gid limit  '+nowpage+','+size+'  ');
        break;
        //如果是员工
        case '3':
          if (ismanage == 1) {
            //统计数量
          if(page == 0){
            var guest_num = await this.model().query(' SELECT count(distinct oat.gid) as num FROM `think_or_allotuser` oat LEFT JOIN `think_or_app_user` au ON oat.uid = au.id LEFT JOIN `think_or_guest` og ON oat.gid = og.id LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE au.xiaozuid = '+jsonshop+' ' + select_info + ' AND og.isdisable = 0 ');
          }
            var guest_info = await this.model().query(' SELECT distinct og.name,og.nickname,og.phone,od.name as shopname,og.sex,og.id,og.headurl,og.lv,og.arrivetime,count(oat.uid) as fuwunum,og.vipcard FROM `think_or_allotuser` oat LEFT JOIN `think_or_app_user` au ON oat.uid = au.id LEFT JOIN `think_or_guest` og ON oat.gid = og.id LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE au.xiaozuid = '+jsonshop+' ' + select_info + ' AND og.isdisable = 0 GROUP BY oat.gid limit  '+nowpage+','+size+'  ');
          } else {
            //如果是员工
            if(page == 0){
            guest_num = await this.model().query(' SELECT distinct count(oat.id) as num FROM `think_or_allotuser` oat LEFT JOIN `think_or_guest` og ON oat.gid = og.id WHERE oat.uid = '+user_id+' ' + select_info + ' AND og.isdisable = 0 ');
            }
            guest_info =  await this.model().query(' SELECT og.name,og.nickname,og.phone,od.name as shopname,og.sex,og.id,og.headurl,og.lv,og.arrivetime,count(oau.uid) as fuwunum,og.vipcard FROM `think_or_allotuser` oa LEFT JOIN `think_or_guest` og ON oa.gid = og.id LEFT JOIN `think_or_department` od ON og.departmentid = od.id LEFT JOIN `think_or_allotuser` oau ON og.id = oau.gid WHERE oa.uid = '+user_id+' '+select_info+' AND og.isdisable = 0 GROUP BY og.id limit '+nowpage+','+size+' ');
          }
        break;
      
      }

      return think.isEmpty(guest_info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'num': guest_num, 'data': guest_info });
    }
    //获取我服务的顾客列表
    async getguestmyfuwuAction(){
      let user_id = this.get('user_id');
      let info = await this.model().query('SELECT og.name,og.phone,od.name as shopname,og.sex,og.id,og.headurl,og.lv,og.arrivetime,count(oau.uid) as fuwunum,og.vipcard FROM `think_or_allotuser` oa LEFT JOIN `think_or_guest` og ON oa.gid = og.id LEFT JOIN `think_or_department` od ON og.departmentid = od.id LEFT JOIN `think_or_allotuser` oau ON og.id = oau.gid WHERE oa.uid = '+user_id+' AND og.isdisable = 0 GROUP BY og.id ');
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info });
    }
    //获取客户的基本信息
    async getguestbaseinfoAction(){
      let guest_id = this.get('guest_id');
      let orcode = this.get('orcode');
      let info = await this.model().query(' SELECT og.name,og.nickname,og.phone,od.name as shopname,og.sex,og.id,og.vipcard,og.headid,og.headurl,og.nickname,og.arrivetime,og.lv FROM `think_or_guest` og LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE og.id = ' + guest_id + ' ');
      //服务该客户的员工数量
      let fuwunum = await this.model().query(' SELECT IFNULL(count(id),0) as fuwunum FROM `think_or_allotuser` WHERE gid = '+guest_id+' ');
      //获取客户现在所在的三期
      let sanqi = await this.model().query('SELECT od.id,IFNULL(ovs.fuwuqi,0) as fuwuqi,IFNULL(ovs.pudianqi,0) as pudianqi FROM `think_or_department` od LEFT JOIN `think_or_vipsanqi` ovs ON od.id = ovs.departmentid WHERE od.orcode = '+orcode+' AND od.floor = 0 AND od.pid = 0 ');
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info,'fuwunum':fuwunum,"sanqi":sanqi[0]});
    }
    //获取指定客户三个月内的消费 消耗 和 到店次数
    async getguestthreemonthinfoAction(){
      let guest_id = this.get('guest_id');
      //获取本月开始的时间戳
      var time_start_benyue = Math.round(new Date(new Date().getFullYear(), new Date().getMonth(), 1).getTime() / 1000);
      //本月结束时间
      var time_end_benyue = Math.round(new Date(new Date().getFullYear(), new Date().getMonth() + 1, 1).getTime() / 1000);
      //获取上月开始的时间戳
      var time_start_shangyue = Math.round(new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1).getTime() / 1000);
      //上月结束时间
      var time_end_shangyue = Math.round(new Date(new Date().getFullYear(), new Date().getMonth(), 1).getTime() / 1000);
      //获取前月开始的时间戳
      var time_start_qianyue = Math.round(new Date(new Date().getFullYear(), new Date().getMonth() - 2, 1).getTime() / 1000);
      //前月结束时间
      var time_end_qianyue = Math.round(new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1).getTime() / 1000);

      let benyue = await this.model().query(' SELECT IFNULL(sum(recemoney),0) as yeji,IFNULL(sum(cardreduce),0) as card,IFNULL(sum(usebalance),0) as usebalance,IFNULL(count(id),0) as num FROM `think_or_shop_order`  WHERE guestid = ' + guest_id + ' AND addtime >= ' + time_start_benyue + ' AND addtime < ' + time_end_benyue + ' AND status <> 0 ');
      let shangyue = await this.model().query(' SELECT IFNULL(sum(recemoney),0) as yeji,IFNULL(sum(cardreduce),0) as card,IFNULL(sum(usebalance),0) as usebalance,IFNULL(count(id),0) as num FROM `think_or_shop_order`  WHERE guestid = ' + guest_id + ' AND addtime >= ' + time_start_shangyue + ' AND addtime < ' + time_end_shangyue + ' AND status <> 0 ');
  
      let qianyue = await this.model().query(' SELECT IFNULL(sum(recemoney),0) as yeji,IFNULL(sum(cardreduce),0) as card,IFNULL(sum(usebalance),0) as usebalance,IFNULL(count(id),0) as num FROM `think_or_shop_order`  WHERE guestid = ' + guest_id + ' AND addtime >= ' + time_start_qianyue + ' AND addtime < ' + time_end_qianyue + ' AND status <> 0 ');



      return think.isEmpty(benyue) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'benyue': benyue, 'shangyue': shangyue, 'qianyue': qianyue });
    }
    //获取客户基本信息的公共方法
    async getguestinfocommeAction(){
      let guest_id = this.get('guest_id');
      let info = await this.model().query(' SELECT og.username,og.name,og.nickname,og.phone,od.name as shopname,og.sex,og.id,og.vipcard,og.headid,og.headurl,og.nickname,og.arrivetime,og.lv,og.balance,og.giftbalance,og.score FROM `think_or_guest` og LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE og.id = ' + guest_id + ' ');
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info});
    } 
    //获取基本档案信息
    async getguestbasearchivesAction(){
      let guest_id = this.get('guest_id');
      var info = await this.model('or_guest_archives').where({ guestid: guest_id }).find();
      if (think.isEmpty(info)) {
        let info_add = await this.model('or_guest_archives').add({ guestid: guest_id });
        let archives_info = await this.model('or_guest_archives').where({ guestid: guest_id }).find();
        return think.isEmpty(archives_info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': archives_info });
      } else {
        return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info });
      }
    }
    //更新客户头像信息
    async updateguestheadAction(){
      let head_info = this.post();
      let info = await this.model('or_guest').where({ id: head_info.guest_id }).update({ headid: head_info.headid, headurl: head_info.headurl });
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info });
    }
    //更新客户档案信息
    async updateguestarchivesAction(){
      let guest_id = this.post('guest_id');
      let data = this.post('info');
      let upinfo = JSON.parse(data);
      let info = await this.model('or_guest_archives').where({ guestid: guest_id }).update(upinfo);
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "更新失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "更新成功...", 'data': info });
    }
    //更新客户基本信息
    async updateguestbaseinfoAction(){
      let guest_id = this.post('guest_id');
      let data = this.post('info');
      let upinfo = JSON.parse(data);
      let info = await this.model('or_guest').where({ id: guest_id }).update(upinfo);
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "更新失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "更新成功...", 'data': info });
    }
    //获取客户账户信息接口
    async getguestaccountinfoAction(){
      let guest_id = this.get('guest_id');
      let info = await this.model().query(' SELECT og.username,og.name,og.nickname,og.phone,od.name as shopname,og.sex,og.id,og.vipcard,og.headid,og.headurl,og.nickname,og.arrivetime,og.lv,og.balance,og.giftbalance,og.score,ogv.vipname FROM `think_or_guest` og LEFT JOIN `think_or_department` od ON og.departmentid = od.id LEFT JOIN `think_or_guest_vipgrade` ogv ON og.level = ogv.id WHERE og.id = ' + guest_id + ' ');
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info});
    }
    //获取客户账户的次卡信息
    async getguestcikalistAction(){
      let guest_id = this.get('guest_id');
      let res = await this.model().query('SELECT os.name,osgs.num,osgs.nownum,od.name as shopname,IFNULL(osc.name,0) as cardname FROM `think_or_shop_guestcardsubject` osgs LEFT JOIN `think_or_subject` os ON osgs.subjectid = os.id LEFT JOIN `think_or_department` od ON osgs.shopid = od.id LEFT JOIN `think_or_shop_card` osc ON osgs.cardid = osc.id WHERE osgs.guestid = '+guest_id+' AND osgs.cardtype = 2 AND osgs.nownum > 0 ');
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': res});
    }
    //获取客户账户的期卡信息
    async getguestqikalistAction(){
      let guest_id = this.get('guest_id');
      let nowtime = Math.round(Date.now()/1000);
      let res = await this.model().query('SELECT os.name,osgs.num,osgs.nownum,od.name as shopname,IFNULL(osc.name,0) as cardname,osgs.endtime FROM `think_or_shop_guestcardsubject` osgs LEFT JOIN `think_or_subject` os ON osgs.subjectid = os.id LEFT JOIN `think_or_department` od ON osgs.shopid = od.id LEFT JOIN `think_or_shop_card` osc ON osgs.cardid = osc.id WHERE osgs.guestid = '+guest_id+' AND osgs.cardtype = 1 AND osgs.endtime >= '+nowtime+' ');
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': res});
    }
    //获取客户暂存商品信息
    async getguestgoodslistAction(){
      let guest_id = this.get('guest_id');
      let res = await this.model().query('SELECT ogs.name as goodsname,osgt.num,osgt.nownum,od.name as shopname,osgt.addtime FROM `think_or_shop_guest_temp_reserve` osgt LEFT JOIN `think_or_goods` ogs ON osgt.goodsid = ogs.id LEFT JOIN `think_or_department` od ON osgt.shopid = od.id WHERE osgt.guestid = '+guest_id+' ');
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': res});
    }
    //获取客户的分类页面信息
    async getguesttypeinfoAction(){
      let guest_id = this.get('guest_id');
      let orcode = this.get('orcode');

      //获取上月开始的时间戳
      var time_start_six = Math.round(new Date(new Date().getFullYear(), new Date().getMonth() - 5, 1).getTime() / 1000);
      //上月结束时间
      var time_end_six = Math.round(new Date(new Date().getFullYear(), new Date().getMonth()+1, 1).getTime() / 1000);

      let info = await this.model().query(' SELECT og.name,og.nickname,og.phone,od.name as shopname,og.sex,og.id,og.vipcard,og.headid,og.headurl,og.nickname,og.arrivetime,og.lv FROM `think_or_guest` og LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE og.id = ' + guest_id + ' ');
      
      let realinfo = await this.model().query(' SELECT IFNULL(sum(recemoney),0) as yeji,IFNULL(count(id),0) as num FROM `think_or_shop_order`  WHERE guestid = ' + guest_id + ' AND addtime >= ' + time_start_six + ' AND addtime < ' + time_end_six + ' AND status <> 0 ');

      let type_info = await this.model().query(' SELECT od.id,IFNULL(A_arrive,0) as A_arrive,IFNULL(A_money,0) as A_money,IFNULL(B_arrive,0) as B_arrive,IFNULL(B_money,0) as B_money,IFNULL(C_arrive,0) as C_arrive,IFNULL(C_money,0) as C_money,IFNULL(D_arrive,0) as D_arrive,IFNULL(D_money,0) as D_money,IFNULL(E_arrive,0) as E_arrive,IFNULL(E_money,0) as E_money FROM `think_or_department` od LEFT JOIN `think_or_guestcategory` ogc ON  ogc.departmentid = od.id WHERE od.orcode = '+orcode+' AND od.floor = 0 AND od.pid = 0  ');
      
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info,type_info:type_info[0],realinfo:realinfo[0]});
    }
    //更新客户的分类信息
    async postguesttypeAction(){
      let guest_id = this.post('guest_id');
      let addinfo = this.post('addinfo');
      let data = JSON.parse(addinfo);
      //console.log(addinfo);
      let res = await this.model('or_guest').where({id:guest_id}).update(data);
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': res });
    }
    //获取客户跟进信息(会员三期)
    async getguestsanqiAction(){
      let guest_id = this.get('guest_id');
      let orcode = this.get('orcode');
      //获取客户基本信息
      let info = await this.model().query(' SELECT og.name,og.nickname,og.phone,od.name as shopname,og.sex,og.id,og.vipcard,og.headid,og.headurl,og.nickname,og.arrivetime,og.lv FROM `think_or_guest` og LEFT JOIN `think_or_department` od ON og.departmentid = od.id WHERE og.id = ' + guest_id + ' ');
      //获取客户跟进状态
      let sanqi = await this.model().query('SELECT od.id,IFNULL(ovs.fuwuqi,0) as fuwuqi,IFNULL(ovs.pudianqi,0) as pudianqi FROM `think_or_department` od LEFT JOIN `think_or_vipsanqi` ovs ON od.id = ovs.departmentid WHERE od.orcode = '+orcode+' AND od.floor = 0 AND od.pid = 0 ');
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info,"sanqi":sanqi[0]});

    }
    //获取客户三期的跟进数据
    async getguestsanqicontentAction(){
      let guest_id = this.get('guest_id');
      let page = this.get('page');
      let size = this.get('size');
      let nowpage = page * size;
      let info = await this.model().query(' SELECT au.name,ogg.id,ogg.title,ogg.content,ogg.addtime FROM `think_or_guest_genjininfo` ogg LEFT JOIN `think_or_app_user` au ON ogg.userid = au.id WHERE ogg.guestid = '+guest_id+' ORDER BY ogg.addtime DESC LIMIT '+nowpage+','+size+' ');
  
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info });
  
    }
    //提交客户三期的跟进状态信息
    async postguestsanqicontentAction(){
      let data = {
      "guestid":this.post('guest_id'),
      "title":this.post('title'),
      "content":this.post('content'),
      "userid":this.post('user_id'),
      "addtime": Math.round(Date.now()/1000)
      }
      let res = await this.model('or_guest_genjininfo').add(data);
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "添加成功...", 'data':''})
    }
    //提交删除跟进信息的请求
    async postguestsanqideleteAction(){
      let id = this.post('id');
      let res = await this.model('or_guest_genjininfo').where({id:id}).delete();
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "删除失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "删除成功...", 'data':''})
    }
    //获取该客户下制定类型的特殊日期
    async getguestspecialdateAction(){
      let guest_id = this.get('guest_id');
      let type = this.get('type');
      let info = await this.model().query(' SELECT ogs.*,og.name FROM `think_or_guest_special_date` ogs LEFT JOIN `think_or_guest` og ON ogs.guestid = og.id WHERE guestid = ' + guest_id + ' AND type = ' + type + ' ORDER BY year,month,day ASC ');

      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info });
    }
    //获取前端提交的特殊日期并保存到数据库
    async postaddguestspecialdateAction(){
      let post_info = this.post('post_info');
      let addinfo = JSON.parse(post_info);
      addinfo['time'] = Math.round(Date.now() / 1000);
      let info = await this.model('or_guest_special_date').add(addinfo);
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "添加失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "添加成功...", 'data': info });
    }
    //删除客户的某条特殊日期记录
    async postdelguestspecialdateAction(){
      let id = this.post('id');
      let res = await this.model('or_guest_special_date').where({id:id}).delete();
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "删除失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "删除成功...", 'data':''})
    }
    //获取客户年度规划信息
    async getguestyearplanAction(){
      let guestid = this.get('guest_id');
      let year = this.get('year');
      let month = this.get('month');
      //获取今年开始的时间戳
      var start_time_year =  Math.round(new Date(year,month-1, 1).getTime()/1000);
      //今年结束时间
      var end_time_year =  Math.round(new Date(year,month, 1).getTime()/1000); 
      //获取年度整体规划业绩
      let info = await this.model().query('SELECT IFNULL(feat,0) as feat FROM `think_plan_year` WHERE year = '+year+' AND guestid = '+guestid+' ');
      let info1 = await this.model().query('SELECT au.name,au.sex,au.headurl,po.id,po.amount,po.arrivetime FROM `think_plan_order` po LEFT JOIN `think_or_app_user` au ON po.userid = au.id WHERE po.guestid = '+guestid+' AND po.arrivetime >= '+start_time_year+' AND po.arrivetime < '+end_time_year+' ');

      return this.json({ 'code': "100", 'msg': "查找成功...", 'year': info,'list':info1 });
    }
    //提交客户规划年度业绩
    async postguestplanyearAction(){
      let guestid = this.post('guest_id');
      let year = this.post('year');
      let text = this.post('text');
      let addtime = Math.round(Date.now() / 1000);
      let res = await this.model().query('SELECT IFNULL(feat,0) as feat FROM `think_plan_year` WHERE year = '+year+' AND guestid = '+guestid+' ');
      if(think.isEmpty(res)){
        let info = await this.model('plan_year').add({'guestid':guestid,'year':year,'feat':text,'addtime':addtime});
        return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "添加失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "添加成功...", 'data': info });
      }else{
        let info = await this.model('plan_year').where({'year':year,'guestid':guestid}).update({'guestid':guestid,'year':year,'feat':text,'addtime':addtime});
        return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "添加失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "添加成功...", 'data': info });
      }
    }
    //获取前端提交的nature（护理\喜好\私密）等信息并保存到数据库
    async postaddguestnatureAction(){
      let post_info = this.post('post_info');
      let addinfo = JSON.parse(post_info);
      addinfo['time'] = Math.round(Date.now() / 1000);
      let info = await this.model('or_guest_nature').add(addinfo);
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "添加失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "添加成功...", 'data': info });
    }
    //获取该客户下指定类型的nature信息
    async getguestnaturedateAction() {
      let guest_id = this.get('guest_id');
      let type = this.get('type');
      let info = await this.model().query(' SELECT * FROM `think_or_guest_nature` WHERE guestid = ' + guest_id + ' AND type = ' + type + ' ORDER BY time DESC ');
      return think.isEmpty(info) ? this.json({ 'code': "200", 'msg': "没有数据...", 'data': '' }) : this.json({ 'code': "100", 'msg': "查找成功...", 'data': info });
    }
    //删除制定日志
    async postdelnaturedateAction(){
      let id = this.post('id');
      let res = await this.model('or_guest_nature').where({id:id}).delete();
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "删除失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "删除成功...", 'data': '' });
    }
    //上传客户相册照片--留档用
    async postaddguestalbumAction(){
      let info = this.post();
      info.time = Math.round(Date.now()/1000);
      let res = await this.model('or_guest_album').add(info);
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "删除失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "删除成功...", 'data': '' });
    }
    //删除客户相册照片--留档用
    async postdelguestalbumAction(){
      let imgid = this.post('imgid');
      let res = await this.model('or_guest_album').where({imgid:imgid}).delete();
      return think.isEmpty(res) ? this.json({ 'code': "200", 'msg': "删除失败...", 'data': '' }) : this.json({ 'code': "100", 'msg': "删除成功...", 'data': '' });
    }


    //buttom
};
